# 导入flask
from flask import Flask, request
from database import db

# 初始化
app = Flask(__name__)


@app.route('/')
def hello():
    return 'hello world'


@app.route('/test1')
def test1():
    return 'test1 hello world'


@app.route('/find')
def find():
    sql = 'select * from tstu'
    res = db.findall(sql)

    for i in res:
        print(i)
    return 'ok'


@app.route('/add', methods=['POST', 'GET'])
def add():
    # request.form  request.args  request.data
    username = request.form.get('username')
    password = request.form.get('password')
    # 给老师表加入数据
    sql = "insert into teacher(username,password) values('%s','%s')" % (username, password)
    db.insert(sql)
    return 'ok'


if __name__ == "__main__":
    app.run(debug=True)